package org.example.aaaatest.xml;

import com.alibaba.fastjson.JSON;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class XmlParser {
    public static void main(String[] args) throws JAXBException {
        String xml = "<route SdkVer=\"3.8.1.0\" Type=\"0x0d\" Flag=\"0x00861078\" Source=\"amap\" Vers=\"5.1\" Uuid=\"93264245839429632\" ContentOptions=\"0x73ec340be\" DisFlag=\"0x1\">" +
                "<location Type=\"0x0A\"/>" +
                "<destination Type=\"2\" Typecode=\"500100\" NaviExtCode=\"2\"/>" +
                "<startpoint Type=\"1\">" +
                "<x>118.839084</x>" +
                "<y>31.911465</y>" +
                "</startpoint>" +
                "<endpoint Type=\"1\">" +
                "<x>118.810758</x>" +
                "<y>31.913138</y>" +
                "</endpoint>" +
                "<avoid Type=\"0\"/>" +
                "</route>";


        JAXBContext jaxbContext = JAXBContext.newInstance(Route.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Route route1 = (Route) unmarshaller.unmarshal(new StringReader(xml));

         //打印或处理route对象
         System.out.println(JSON.toJSONString(route1));


    }



}
